﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

namespace VSM
{
    public partial class Popup_DealerLabour : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSequence();
            }
        }

        private void LoadSequence() {
            
            Services sv = new Services();

            string sql = "select ROW_NUMBER() OVER(ORDER BY DealerCode ASC) AS RowNum, DealerCode, DealerName, LabourCharge, UpdatedDate from U_LabourDealer ";
            Session["LabourCharge"] = sv.ExecuteQuery("DEALER", sql).Tables[0];
            gvLabour.DataSource = (DataTable)Session["LabourCharge"];
            gvLabour.DataBind();
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            Services sv = new Services();
            DataSet dsDetail = new DataSet();
            DataTable dtAdd = new DataTable();
            //LabourID
            dtAdd.Columns.Add("DealerCode");
            dtAdd.Columns.Add("LabourCharge");

            foreach (GridViewRow row in gvLabour.Rows)
            {
                dsDetail.Tables.Clear();
                dtAdd.Rows.Clear();
                DataRow drAdd = dtAdd.NewRow();
                drAdd["DealerCode"] = ((Label)row.FindControl("lb_DealerCode")).Text;
                drAdd["LabourCharge"] = ((TextBox)row.FindControl("txt_LabourCharge")).Text;
                dtAdd.Rows.Add(drAdd);
                dsDetail.Tables.Add(dtAdd);

                sv.UpdateDealerLabour("DEALER", dsDetail);
            }

            this.lb_Message.Text = "Update complete.";
            this.lb_Message.Visible = true;
        }
    }
}